//
//  CertificationViewController.m
//  OneCreditTreasure
//
//  Created by iOS Grouper on 16/8/25.
//
//

#import "CertificationViewController.h"
#import "MDetailSettingViewController.h"

@interface CertificationViewController ()
/** 认证信息label */
@property (nonatomic, strong) UILabel *certificationLB;
/** 重新认证button */
@property (nonatomic, strong) UIButton *confirmBtn;
@end

@implementation CertificationViewController
#pragma mark - 生命周期 life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self certificationLB];
}

- (instancetype)init {
    if (self = [super init]) {
        self.title = @"实名认证";
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(succeedToCertificate:)];
    }
    return self;
}

#pragma mark - 方法 methods
- (void)succeedToCertificate:(UIButton *)sender {
    NSArray *views = self.navigationController.viewControllers;
    for (id view in views) {
        if ([view isKindOfClass:[MDetailSettingViewController class]]) {
            [self.navigationController popToViewController:view animated:YES];
        }
    }
}

- (void)reCertificate:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 懒加载 lazy loading
- (UILabel *)certificationLB {
    if(_certificationLB == nil) {
        _certificationLB = [[UILabel alloc] init];
        [self.view addSubview:_certificationLB];
        [_certificationLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(0);
        }];
        _certificationLB.text = ([[NSUserDefaults standardUserDefaults] boolForKey:@"认证信息"] == YES ? @"认证成功" : @"认证失败");
        _certificationLB.textAlignment = NSTextAlignmentCenter;
        self.confirmBtn.hidden = [[NSUserDefaults standardUserDefaults] boolForKey:@"认证信息"];
    }
    return _certificationLB;
}

- (UIButton *)confirmBtn {
    if(_confirmBtn == nil) {
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.view addSubview:_confirmBtn];
        [_confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(0);
            make.height.equalTo(44);
        }];
        [_confirmBtn setTitle:@"重新认证" forState:UIControlStateNormal];
        _confirmBtn.backgroundColor = kRGBA(0, 0, 0, 0.8);
        [_confirmBtn addTarget:self action:@selector(reCertificate:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmBtn;
}

@end
